package drone;

import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.Matrix3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;
import java.util.ArrayList;

/**
 *
 * @author Robert Verginien Nickel
 */
public class SpacePainter extends Geometry{
    
    AssetManager assetManager;
    DataBaseSpaces dbs = DataBaseSpaces.getInstance();
    Spatial foot;
    Spatial arm;
    
    /**
     * @param assetManager
     * @param node 
     */
    public SpacePainter(AssetManager assetManager, Node node){
        super();
        this.assetManager = assetManager;
        paintSpaces(node);
        paintPedGate(node);
        paintPlane(node);
    }
    
    /**
     * This paints all Spaces that are set up in the DataBaseSpaces.txt
     * @param node to paint on
     */
    private void paintSpaces(Node node){
        paintRechargePoint(node);
        
        ArrayList<Space> spaces = dbs.getAllSpaces();
        for(int i = 0; i < spaces.size(); i++){
            Box boxMesh = new Box(3.4f,0f,1.2f); //Size of one Space
            Geometry geom = new Geometry("geometry", boxMesh);
            Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 
            Texture monkeyTex = assetManager.loadTexture("Interface/space.png"); 
            boxMat.setTexture("ColorMap", monkeyTex); 
            geom.setMaterial(boxMat);            
            geom.setLocalTranslation((float)spaces.get(i).getCoordinates().getxPos(),0,(float)spaces.get(i).getCoordinates().getzPos());
            node.attachChild(geom);
        }
    }
    /**
     * this paints the recharging paint with the battery-texture
     * @param node to paint on
     */
    private void paintRechargePoint(Node node){
        Box boxMesh = new Box(0.5f,0.5f,0f);
        Geometry geom = new Geometry("geometry", boxMesh);
        Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 
        Texture monkeyTex = assetManager.loadTexture("Interface/Recharge.png"); 
        boxMat.setTexture("ColorMap", monkeyTex); 
        geom.setMaterial(boxMat);            
        geom.setLocalRotation(new Matrix3f(1, 0, 0, 0, 0, -1, 0, 1, 0)); //Rotation around x-Axis
        geom.setLocalTranslation(0.0f,0f,10.0f);
        node.attachChild(geom);
    }
    /**
     * this paints the palm as a sign for the point, the pedestrians want to reach
     * in reality, everyone would like to park near by
     * @param node to paint on
     */
    private void paintPedGate(Node node){
        Spatial pedGate = assetManager.loadModel("Models/Palm_Tree.obj");
        Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        pedGate.setMaterial(mat_default);
        pedGate.setLocalTranslation(0f,0f,0f);
        pedGate.scale(0.1f);
        pedGate.rotate(-1.57f, 0, 0);
        node.attachChild(pedGate);
    }
    /**
     * this paints the grey ground
     * @param node to paint on
     */
    private void paintPlane(Node node){
        Box boxMesh = new Box(100f, 100f, 0f);
        Geometry geom = new Geometry("geometry", boxMesh);
        Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 
        Texture greyTex = assetManager.loadTexture("Interface/plane.png"); 
        boxMat.setTexture("ColorMap", greyTex); 
        geom.setMaterial(boxMat);            
        geom.setLocalRotation(new Matrix3f(1, 0, 0, 0, 0, -1, 0, 1, 0)); //Rotation around x-Axis
        geom.setLocalTranslation(75f,-0.01f,75f);
        node.attachChild(geom);
    }
}
